<?php
class Group extends AppModel
{
    /**
     * associations
     */
    var $hasMany = array(
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'group_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        ),
        'MenuGroup' => array(
            'className' => 'MenuGroup',
            'foreignKey' => 'group_id',
            'dependent' => false,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'exclusive' => '',
            'finderQuery' => '',
            'counterQuery' => ''
        )
    );


    function getGroupById($id=null){
        $condition_array = array('Group.id' =>$id, 'Group.deleted' => 'n','Group.hidden' => '0');
        $data = $this->find('first',array(
            'conditions'=>$condition_array,
            'recursive'=>-1
        ));
        return $data;
    }


    function getGroups(){
        $condition_array = array('Group.deleted' => 'n','Group.hidden' => '0');
        $data = $this->find('all',array(
            'conditions'=>$condition_array,
            'recursive'=>-1
        ));
        $arr = array();
        foreach($data as $d){
            $arr[]= array(
                'id'=>$d['Group']['id'],
                'name'=>$d['Group']['name']
            );
        }

        return $arr;

    }

}